<?php
class _Users extends TableBase {
	
	function init(){
		$this->addLoaderVariable('id', 'Auto');
		$this->addLoaderVariable('name', 'Text');
		$this->addLoaderVariable('username', 'Text', 'NULL', 'u', '20', true);
		$this->addLoaderVariable('password', 'MD5', 'NULL', '', null, true);
	}
	
	function login($username, $password){
		$sql = "SELECT `id` 
		FROM `".$this->_tableName."` 
		WHERE `username` = '".$username."' 
		AND `password` = '".md5($password)."' 
		LIMIT 1
		";
		$db = F::get()->DB();
		$userID = $db->getSingleResult( $sql );
		
		return $userID;
	}
	
	function post($postdata){
		switch($postdata['switch']){
			case 'insert':{
				$db = F::get()->DB();
				if( $db->insertViaArray( $postdata['datatypeVal'], $this->_tableName  ) ){
					F::get()->Tpl()->addMessage('Users','User inserted');
				}else{
					F::get()->Tpl()->addMessage('Users','User couldnt be added', 'error');
				}
				//F::get()->Tpl()->redirect('home');
				break;
			}
		}
	}
}
?>
